package tech.aistar.day01;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 本类功能:
 *
 * @author cxylk
 * @date 2020/9/15 18:24
 */
@WebServlet(urlPatterns = "/day01/get")
public class GetAction extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //判断请求是get还是post
        System.out.println(req.getMethod());
        System.out.println("service");
    }

    /**
     * 如果发送了一个post请求，但是使用doGet方法来接收，那么将会抛出
     * HTTP Status 405 - HTTP method POST is not supported by this URL
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
//    @Override
//    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        System.out.println("只能接收get请求...");
//    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
